<?php include load_template('_subnav.php')?>
<style type="text/css" media="screen">
/* <![CDATA[ */
    div.acl {
        float:left;
        width:200px;
        margin:4px;
        padding:2px;
        border:1px dashed #e9e9e9;
    }
    .acl_perms {
        font-size:xx-small;
        height:20px;
        line-height:20px;
    }    

/* ]]> */
</style>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
// ]]>
</script>
<h1>Role Management</h1>

<h3><?php echo link_to('Add New Role',array('controller'=>'admin/roles' )
)?></h3>

<!-- Select User To Manage -->
<div id="select_new">
<?php echo form_tag('index',array('method'=>'get'))?>
Get Details For: <?php echo select_tag('id',options_for_select($all_roles, (int) @$_REQUEST['id']))?>
<?php echo submit_tag('Edit')?>
<?php echo end_form_tag()?>
</div>


<?php echo error_messages_for('roles')?>
<h2><?php if(!empty($role)) echo "Managing Role: <span style='color:red'>{$role['role_name']}</span>" ?></h2>
<?php
    if ( empty($role) )
    {
?>
<div id="tabPanel1" class='tab-pane'>    
        <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Add Role</h2>      
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','add_role')?>
        <?php include load_template('_form.php')?>
        <?php echo submit_tag('Add Role')?>
        <?php echo end_form_tag()?>
    </div>
</div>
<?php } else { ?>
  <div id="tabPanel" class='tab-pane'>    
    <div id="tabPage1" class='tab-page'>
        <h2 class='tab'>Edit role details</h2>
        <?php echo form_tag('index',array('validation'=>true))?>
        <?php echo hidden_field_tag('action','edit_role')?>
        <?php include load_template('_form.php')?>
        <?php echo hidden_field('roles','id')?>
        <?php echo submit_tag('Edit Role')?>
        <?php echo end_form_tag()?>
        
        <div class='div-delete'>
        <?php echo  form_tag('delete') ?>
        <?php echo  hidden_field_tag('id',$role['id']) ?>
        <?php echo  hidden_field_tag('action','delete') ?>
        <span style='color:red;font-weight:bold'>Delete This Role?</span>
        <?php echo  submit_tag('Delete Role',array('confirm'=>'Are you sure you want to delete this role?','class'=>'submit_delete')) ?>
        <?php echo  end_form_tag() ?>
        
        </div>
                
        
    </div>
    
    <div id="tabPage2" class='tab-page'>
        <h2 class='tab'>Users who have this role</h2>
        <div class='user_roles' style='width:350px;'>
        <?php echo form_remote_tag(array('controller'=>'admin/roles' ,'action'=>'modify_role_users'),
                array(
                    'name'=>'user_roles',
                    'update'=>'success_messages',
                    'before'=>"selectAll('users[]')",
                    'complete'=>"toggle_success();",
                    )
                    )
         ?>
        <?php echo hidden_field_tag('role_id', $role['id'])?>
        <?php echo select_transfer('users[]', array_diff($all_users,$role_users), $role_users)?>  
        <p><?php echo submit_tag('Modify Roles')?></p>
        <?php echo end_form_tag()?>
       </div>
    </div>
    
    <div id="tabPage3" class='tab-page'>
        <h2 class='tab'>Permissions for this role</h2>
        <div id='role_permissions'>
<!--    radio buttons   -->
        <?php include load_template('_permissions.php')?>
                <br style='clear:both'>
        </div>
    </div>
    </div>
<?php } ?>

    <script type="text/javascript">
        setupAllTabs();
    </script>
        <h2>Role Crib Sheet:</h2>
    <div class='section'>
    <p><b>Administrator</b>: Can pretty much do anything. Full user control, access to every tool.</p>    
    <p><b>Editor</b>: Can manage files, write news and pages. Can also edit page templates and view inbox leads.</p>
    <p><b>Author</b>: Can write news, pages, and access the files area.</p>
    <p><b>Contributor</b>: Can only upload files and write/edit news stories.</p>
    </div>
